
#include "bsp_driver_gpio.h"

/****************************************************                        
*				stm32f103x_bsp_init_Uart1RxGPIO
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_UartRxGPIO( GPIO_TypeDef *p_Def,
									  uint32_t      u_clk,
									  uint16_t      u_pin ){


	GPIO_InitTypeDef   gpio;

	bsp_assert( p_Def );

	bsp_assert ( IS_GET_GPIO_PIN( u_pin ) );

	RCC_APB2PeriphClockCmd( u_clk ,ENABLE );

	gpio.GPIO_Pin					= u_pin;
	gpio.GPIO_Speed					= GPIO_Speed_50MHz;
	gpio.GPIO_Mode					= GPIO_Mode_IN_FLOATING;

	GPIO_Init( p_Def, &gpio);
}

/****************************************************                        
*				stm32f103x_bsp_init_Uart1TxGPIO
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_UartTxGPIO( GPIO_TypeDef *p_Def,
									  uint32_t      u_clk,
									  uint16_t      u_pin ){

	GPIO_InitTypeDef   gpio;
	
	bsp_assert( p_Def );
	
	bsp_assert ( IS_GET_GPIO_PIN( u_pin ) );
	
	RCC_APB2PeriphClockCmd( u_clk ,ENABLE );
	
	gpio.GPIO_Pin					= u_pin;
	gpio.GPIO_Speed					= GPIO_Speed_50MHz;
	gpio.GPIO_Mode					= GPIO_Mode_AF_PP;
	
	GPIO_Init( p_Def, &gpio);

}

/****************************************************                        
*				stm32f103x_bsp_init_SPI1_CC2500_PIN
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_SPI2_CC2500_PIN( GPIO_TypeDef *p_Def,
										  uint32_t      u_clk,
										  uint16_t      u_pin ){

	GPIO_InitTypeDef   gpio;
	
	bsp_assert( p_Def );
	
	bsp_assert ( IS_GET_GPIO_PIN( u_pin ) );
	
	RCC_APB2PeriphClockCmd( u_clk ,ENABLE );

	gpio.GPIO_Pin					= u_pin;
	gpio.GPIO_Speed					= GPIO_Speed_50MHz;
	gpio.GPIO_Mode					= GPIO_Mode_AF_PP;
	
	GPIO_Init( p_Def, &gpio);

}
/****************************************************                        
*				stm32f103x_bsp_init_SPI1_CC2500_CS
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_SPI2_CC2500_CS( GPIO_TypeDef *p_Def,
										  uint32_t      u_clk,
										  uint16_t      u_pin ){

	GPIO_InitTypeDef   gpio;
	
	bsp_assert( p_Def );
	
	bsp_assert ( IS_GET_GPIO_PIN( u_pin ) );
	
	RCC_APB2PeriphClockCmd( u_clk ,ENABLE );
	
	gpio.GPIO_Pin					= u_pin;
	gpio.GPIO_Speed					= GPIO_Speed_50MHz;
	gpio.GPIO_Mode					= GPIO_Mode_Out_PP;
	
	GPIO_Init( p_Def, &gpio);

}
/****************************************************                        
*				stm32f103x_bsp_init_SPI1_CC2500_LAN
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_SPI2_CC2500_LAN( GPIO_TypeDef *p_Def,
										  uint32_t      u_clk,
										  uint16_t      u_pin ){

	GPIO_InitTypeDef gpio;
	

	RCC_APB2PeriphClockCmd(u_clk, ENABLE);
	
	gpio.GPIO_Pin   = u_pin;
	gpio.GPIO_Mode  = GPIO_Mode_Out_PP;
	gpio.GPIO_Speed = GPIO_Speed_50MHz;

	GPIO_Init(p_Def, &gpio);
}

/****************************************************                        
*				stm32f103x_bsp_init_SPI2_CC2500_PA
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_SPI2_CC2500_PA( GPIO_TypeDef *p_Def,
										uint32_t      u_clk,
										uint16_t      u_pin ){

	GPIO_InitTypeDef gpio;
	
	
	RCC_APB2PeriphClockCmd(u_clk, ENABLE);
	
	gpio.GPIO_Pin   = u_pin;
	gpio.GPIO_Mode  = GPIO_Mode_Out_PP;
	gpio.GPIO_Speed = GPIO_Speed_50MHz;
	
	GPIO_Init(p_Def, &gpio);

}

/****************************************************                        
*				stm32f103x_bsp_init_SPI1_CC2500_GDO0
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_SPI2_CC2500_GDO0( GPIO_TypeDef *p_Def,
										   uint32_t      u_clk,
										   uint16_t      u_pin ){
	GPIO_InitTypeDef gpio;
	
	RCC_APB2PeriphClockCmd(u_clk, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); 

	gpio.GPIO_Pin   = u_pin;
	gpio.GPIO_Mode  = GPIO_Mode_IPU;
	gpio.GPIO_Speed = GPIO_Speed_50MHz;
	
	GPIO_Init(p_Def, &gpio);
}

//////////////////////////////////////////////////////////////////////////
/****************************************************                        
*				stm32f103x_bsp_init_SPI3_CC3000_PIN
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_SPI3_CC3000_PIN(  ){

	GPIO_InitTypeDef GPIOInit;
	
	/* Enable SPI and GPIO clocks */
	RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |
						    RCC_APB2Periph_GPIOB |
							RCC_APB2Periph_AFIO, ENABLE );
	
	RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI3, ENABLE);

	/* Configure SPI pins: SCK, MISO and MOSI */
	GPIOInit.GPIO_Pin		= GPIO_Pin_3 | GPIO_Pin_5;
	GPIOInit.GPIO_Mode		= GPIO_Mode_AF_PP;
	GPIOInit.GPIO_Speed		= GPIO_Speed_50MHz;

	GPIO_Init(GPIOB, &GPIOInit);
	
	GPIOInit.GPIO_Pin		= GPIO_Pin_4;
	GPIOInit.GPIO_Mode		= GPIO_Mode_AF_OD;
	GPIOInit.GPIO_Speed		= GPIO_Speed_50MHz;

	GPIO_Init(GPIOB, &GPIOInit);
	
	/* Configure I/O for Flash Chip select */
	GPIOInit.GPIO_Pin		= GPIO_Pin_15;
	GPIOInit.GPIO_Mode		= GPIO_Mode_Out_PP;
	GPIOInit.GPIO_Speed		= GPIO_Speed_50MHz;

	GPIO_Init(GPIOA, &GPIOInit);
	/* Enable the FLASH: Chip Select Low */
	
}

/****************************************************                        
*				stm32f103x_bsp_init_LED_PIN
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
/****************************************************                        
*				stm32f103x_bsp_init_LED_PIN
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_LED_PIN(  void ){
	
	GPIO_InitTypeDef GPIOInit;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOD, ENABLE);
	
	
	GPIOInit.GPIO_Pin		= GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
	GPIOInit.GPIO_Speed		= GPIO_Speed_50MHz;
	GPIOInit.GPIO_Mode		= GPIO_Mode_Out_PP;
	
	GPIO_Init(GPIOE, &GPIOInit);

	GPIOInit.GPIO_Pin		= GPIO_Pin_14|GPIO_Pin_15;
	GPIOInit.GPIO_Speed		= GPIO_Speed_50MHz;
	GPIOInit.GPIO_Mode		= GPIO_Mode_Out_PP;
	
	GPIO_Init(GPIOD, &GPIOInit);
}
